package com.dfbz.demo;

import com.sun.org.apache.bcel.internal.generic.NEW;
import sun.font.FontRunIterator;

import java.util.Calendar;
import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo04_回顾Thread执行不同的任务 {


    public static void main(String[] args) throws Exception {

        TaskCallable taskCallable = new TaskCallable();

        FutureTask<Integer> futureTask = new FutureTask(taskCallable);

        // 开启一个新的线程执行Callable任务
        Thread thread = new Thread(futureTask);
        thread.start();

        for (int i = 0; i < 10000; i++) {
            System.out.println("我是main...");
        }

        Integer result = futureTask.get();

        System.out.println("结果集为: " + result);
    }

    public static void test(String[] args) {


        TaskRunnable taskRunnable = new TaskRunnable();

        Thread thread = new Thread(taskRunnable);
        thread.start();

        for (int i = 0; i < 10000; i++) {
            System.out.println("我是main...");
        }
    }
}

class TaskCallable implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        for (int i = 0; i < 10000; i++) {
            System.out.println("TaskCallable");
        }
        return 0;
    }
}


class TaskRunnable implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 10000; i++) {
            System.out.println("TaskRunnable");
        }
    }
}
